package com.clock.shop.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.clock.common.enums.shop.ServiceStatus;
import com.clock.common.utils.DateUtils;
import com.clock.common.utils.bean.BeanUtils;
import com.clock.shop.domain.ShopService;
import com.clock.shop.domain.ShopShop;
import com.clock.shop.domain.vo.ShopServiceVo;
import com.clock.shop.domain.vo.ShopShopVo;
import com.clock.shop.mapper.ShopServiceMapper;
import com.clock.shop.service.IShopServiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;


/**
 * 服务信息Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-10-11
 */
@Service
public class ShopServiceServiceImpl implements IShopServiceService
{
    @Resource
    private ShopServiceMapper shopServiceMapper;

    @Autowired
    private ShopShopServiceImpl shopShopService;
    /**
     * 查询服务信息
     * 
     * @param serviceId 服务信息主键
     * @return 服务信息
     */
    @Override
    public ShopServiceVo selectShopServiceByServiceId(Long serviceId)
    {
        ShopService shopService = shopServiceMapper.selectShopServiceByServiceId(serviceId);
        // 获取店铺信息
        ShopShopVo shopShopVo = shopShopService.selectShopShopByShopId(shopService.getShopId());
        ShopServiceVo shopServiceVo=new ShopServiceVo();
        // 如果服务信息不为空，则将服务信息转换为ShopServiceVo
        if(shopService!=null){
            BeanUtils.copyProperties(shopService,shopServiceVo);
            shopServiceVo.setShopName(shopShopVo.getShopName());
            // 设置服务状态
            if(shopService.getIsDeleted().equals( ServiceStatus.LAUNCHING.getCode())){
                shopServiceVo.setServiceStatus(ServiceStatus.LAUNCHING.getMessage());
            }else {
                shopServiceVo.setServiceStatus(ServiceStatus.REMOVE.getMessage());
            }
        }

        return  shopServiceVo;
    }

    /**
     * 查询服务信息列表
     * 
     * @param shopServiceVo 服务信息
     * @return 服务信息
     */
    @Override
    public List<ShopServiceVo> selectShopServiceList(ShopServiceVo shopServiceVo)
    {
        List<ShopServiceVo> shopServiceVos = shopServiceMapper.selectShopServiceList(shopServiceVo);
        for (ShopServiceVo shopServiceVo1 : shopServiceVos)
        {
            if(shopServiceVo1.getIsDeleted().equals( ServiceStatus.LAUNCHING.getCode())){
                shopServiceVo1.setServiceStatus(ServiceStatus.LAUNCHING.getMessage());
            }else {
                shopServiceVo1.setServiceStatus(ServiceStatus.REMOVE.getMessage());
            }
        }
        return shopServiceVos;
    }

    /**
     * 新增服务信息
     * 
     * @param shopServiceVo 服务信息
     * @return 结果
     */
    @Override
    public int insertShopService(ShopServiceVo shopServiceVo)
    {
        // 根据店铺名获取店铺id
        List<ShopShop> shopShops = shopShopService.selectShopShopByShopName(shopServiceVo.getShopName());
        ShopService shopService = new ShopService();
        // 设置店铺id
        if(shopShops.size()!=0){
            BeanUtils.copyProperties(shopServiceVo,shopService);
            shopService.setShopId(shopShops.get(0).getShopId());
        }
        shopService.setUpdateTime(DateUtils.getNowDate());
        return shopServiceMapper.insertShopService(shopService);
    }

    /**
     * 修改服务信息
     * 
     * @param shopServiceVo 服务信息
     * @return 结果
     */
    @Override
    public int updateShopService(ShopServiceVo shopServiceVo)
    {
        // 根据店铺名获取店铺id
        List<ShopShop> shopShops = shopShopService.selectShopShopByShopName(shopServiceVo.getShopName());
        ShopService shopService = new ShopService();
        // 设置店铺id
        if(shopShops.size()!=0){
            BeanUtils.copyProperties(shopServiceVo,shopService);
            shopService.setShopId(shopShops.get(0).getShopId());
        }
        shopService.setUpdateTime(DateUtils.getNowDate());
        return shopServiceMapper.updateShopService(shopService);
    }

    /**
     * 批量删除服务信息
     * 
     * @param serviceIds 需要删除的服务信息主键
     * @return 结果
     */
    @Override
    public int deleteShopServiceByServiceIds(Long[] serviceIds)
    {
        return shopServiceMapper.deleteShopServiceByServiceIds(serviceIds);
    }

    /**
     * 删除服务信息信息
     * 
     * @param serviceId 服务信息主键
     * @return 结果
     */
    @Override
    public int deleteShopServiceByServiceId(Long serviceId)
    {
        return shopServiceMapper.deleteShopServiceByServiceId(serviceId);
    }
}
